package com.chukun.flink.stream.action.fraud.rules.functions;

import com.chukun.flink.stream.action.fraud.source.BaseGenerator;

import java.util.SplittableRandom;

/**
 * @author chukun
 * @version 1.0.0
 * @description 静态规则生成器
 * @createTime 2022年05月22日 15:49:00
 */
public class RulesStaticJsonGenerator extends BaseGenerator<String> {

    private static final String[] RULES =
            new String[] {
                    "{\"ruleId\":\"1\","
                            + "\"aggregateFieldName\":\"paymentAmount\","
                            + "\"aggregatorFunctionType\":\"SUM\","
                            + "\"groupingKeyNames\":[\"payeeId\", \"beneficiaryId\"],"
                            + "\"limit\":\"20000000\","
                            + "\"limitOperatorType\":\"GREATER\","
                            + "\"ruleState\":\"ACTIVE\","
                            + "\"windowMinutes\":\"43200\"}",
                    "{\"ruleId\":\"2\","
                            + "\"aggregateFieldName\":\"COUNT_FLINK\","
                            + "\"aggregatorFunctionType\":\"SUM\","
                            + "\"groupingKeyNames\":[\"paymentType\"],"
                            + "\"limit\":\"300\","
                            + "\"limitOperatorType\":\"LESS\","
                            + "\"ruleState\":\"PAUSE\","
                            + "\"windowMinutes\":\"1440\"}",
                    "{\"ruleId\":\"3\","
                            + "\"aggregateFieldName\":\"paymentAmount\","
                            + "\"aggregatorFunctionType\":\"SUM\","
                            + "\"groupingKeyNames\":[\"beneficiaryId\"],"
                            + "\"limit\":\"10000000\","
                            + "\"limitOperatorType\":\"GREATER_EQUAL\","
                            + "\"ruleState\":\"ACTIVE\","
                            + "\"windowMinutes\":\"1440\"}",
                    "{\"ruleId\":\"4\","
                            + "\"aggregateFieldName\":\"COUNT_WITH_RESET_FLINK\","
                            + "\"aggregatorFunctionType\":\"SUM\","
                            + "\"groupingKeyNames\":[\"paymentType\"],"
                            + "\"limit\":\"100\","
                            + "\"limitOperatorType\":\"GREATER_EQUAL\","
                            + "\"ruleState\":\"ACTIVE\","
                            + "\"windowMinutes\":\"1440\"}",
            };

    @Override
    public String randomEvent(SplittableRandom rnd, long id) {
        if (id >= 0 && id < RULES.length) {
            return RULES[(int) id];
        } else {
            return null;
        }
    }
}
